package reno.market.mainmarket.warframemarket.dao;

import org.hibernate.Session;
import org.hibernate.query.NativeQuery;
import org.springframework.stereotype.Repository;
import reno.market.mainmarket.common.HibernateUtils;
import reno.market.mainmarket.warframemarket.entity.WarframemarketEO;
import reno.market.mainmarket.warframemarket.entity.WarframemarketkeywordEO;

import java.util.List;

@Repository
public class WarframeMarketDao {
    public List<WarframemarketkeywordEO> queryKeywordFull(String keyword) {
        String keywordsql = "select * FROM WarframeMarketKeyWord a WHERE a.item_cn LIKE '%TARGET%' ORDER BY a.id";
        //使用简称去数据库查询物品全名
        Session session = HibernateUtils.getSession();
        keywordsql = keywordsql.replace("TARGET", keyword);
        NativeQuery<WarframemarketkeywordEO> queryKeyWorkFull = session.createNativeQuery(keywordsql, WarframemarketkeywordEO.class);
        List<WarframemarketkeywordEO> result = queryKeyWorkFull.getResultList();
        session.close();
        return result;
    }

    public List<WarframemarketEO> queryItemInfo(String queryStr) {
        String targetsql = "select * from WarframeMarket a where a.item_cn like '%TARGET%' order by a.item_cn";
        Session session = HibernateUtils.getSession();
        NativeQuery<WarframemarketEO> queryTarget = session.createNativeQuery(targetsql.replace("TARGET", queryStr), WarframemarketEO.class);
        List<WarframemarketEO> result = queryTarget.getResultList();
        session.close();
        return result;
    }
}
